From 900b9f137910c0ad0fe95d7354af8315ffeb0b04 Mon Sep 17 00:00:00 2001
From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Date: Mon, 22 Apr 2019 18:39:52 +0200
Subject: [PATCH] CMake: add USE_STATIC option

USE_STATIC will:
 - always link statically with external libraries (such as glib2)
 - will not set rpath to avoid the following error:

CMake Error at cmake_install.cmake:50 (file):
  file RPATH_CHANGE could not write new RPATH:

    /usr/lib

  to the file:

    /home/fabrice/br-test-pkg/br-arm-full-static/target/usr/bin/tshark

  No valid ELF RPATH or RUNPATH entry exists in the file;

Change-Id: I242dc1a091cc211ee891568a2dee5080c9974fba
Ping-Bug: 15713
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Reviewed-on: https://code.wireshark.org/review/32945
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
[Retrieved from:
https://github.com/wireshark/wireshark/commit/900b9f137910c0ad0fe95d7354af8315ffeb0b04]
---
 CMakeLists.txt   | 6 +++++-
 CMakeOptions.txt | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index df62819651..e2fdafc227 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -185,7 +185,7 @@ set(PROJECT_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
 set(LIBRARY_INSTALL_RPATH "")
 set(EXECUTABLE_INSTALL_RPATH "")
 set(EXTCAP_INSTALL_RPATH "")
-if(NOT (WIN32 OR APPLE))
+if(NOT (WIN32 OR APPLE OR USE_STATIC))
 	# Try to set a RPATH for installed binaries if the library directory is
 	# not already included in the default search list.
 	list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
@@ -325,6 +325,10 @@ if(OSS_FUZZ)
 		message(FATAL_ERROR "Cannot force libFuzzer when using oss-fuzz")
 	endif()
 	# Must not depend on external dependencies so statically link all libs.
+	set(USE_STATIC ON)
+endif()
+
+if(USE_STATIC)
 	set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
 endif()
 
diff --git a/CMakeOptions.txt b/CMakeOptions.txt
index b99e949c44..a605f7b49c 100644
--- a/CMakeOptions.txt
+++ b/CMakeOptions.txt
@@ -59,6 +59,7 @@ if(WIN32)
 	option(ENABLE_AIRPCAP    "Enable AirPcap support" ON)
 endif()
 option(ENABLE_STATIC            "Build Wireshark libraries statically" OFF)
+option(USE_STATIC               "Always link statically with external libraries" OFF)
 option(ENABLE_PLUGINS           "Build with plugins" ON)
 option(ENABLE_PLUGIN_IFDEMO     "Build with plugin interface demo" OFF)
 option(ENABLE_PCAP_NG_DEFAULT   "Enable pcapng as default file format" ON)
